package com.heima.user.common;


import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 如果把他配置在Common模块，默认是不会生效的，因为所在的包不一样，其它微服务的扫描包不一致，无法被扫描到
 */
@Configuration
@ConditionalOnClass(DispatcherServlet.class)//就是配置只在有DispatcherServlet的情况下生效
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInfoInterceptor());
    }
}